def solve(nums):
    n=len(nums)
    res_n=n
    if n==3:
        if nums[0]==nums[1]==nums[3]:
            nums[:]=nums[1:]
            return 2
        else:
            return 3
    else:
        for i in range(n-2):
            if nums[i]==nums[i+1]==nums[i+2]:
                nums[i]=float("inf")
                res_n-=1
    res=[num for num in nums if num!=float("inf")]
    nums[:]=res

    return n

if __name__=="__main__":
    nums=[1,1,1,2,2,3]
    print(solve(nums))
    print(nums)